<template>
    <box left="50px"
         top="720px"
         title="卡萨帝自占比">
        <div class='leftbottom'>
            <my-marquee :info="info.info"></my-marquee>
            <my-title></my-title>
            <div class="chart"
                 ref="chart"></div>
            <div class="list flex space-between">
                <div class="item flex">
                    <img src="../../../assets/img/home/tm-icon-2.png"
                         alt="">
                    <div class="data">
                        <span class="val">{{info.tm?info.tm:""}}</span>
                    </div>
                </div>
                <div class="item flex">
                    <img src="../../../assets/img/home/jd-icon-2.png"
                         alt="">
                    <div class="data">
                        <span class="val">{{info.jd?info.jd:""}}</span>
                    </div>
                </div>
                <div class="item flex">
                    <img src="../../../assets/img/home/sn-icon-2.png"
                         alt="">
                    <div class="data">
                        <span class="val">{{info.sn?info.sn:""}}</span>
                    </div>
                </div>
                <div class="item flex">
                    <img src="../../../assets/img/home/gm-icon-2.png"
                         alt="">
                    <div class="data">
                        <span class="val">{{info.gm?info.gm:""}}</span>
                    </div>
                </div>
            </div>
        </div>
    </box>

</template>

<script>
export default {
    props: {
        info: {},
    },
    watch: {
        info: {
            handler(newVal) {
                this.chartInit(
                    newVal.tmChartData,
                    newVal.jdChartData,
                    newVal.xData
                )
            },
            deep: true,
        },
    },
    methods: {
        chartInit(tmData, jdData, xData) {
            let _chart = this.$echarts.init(this.$refs['chart'])
            let _options = {
                grid: {
                    top: '40',
                    right: '20',
                    left: '30',
                    bottom: '30', //图表尺寸大小
                },
                legend: {
                    textStyle: {
                        color: '#8fadcc',
                        fontSize: 12,
                    },
                    itemWidth: 8,
                    itemHeight: 4,

                    right: 0,
                    top: 10,
                },
                tooltip: {},
                xAxis: {
                    type: 'category',
                    color: '#59588D',
                    data: xData,
                    axisLabel: {
                        margin: 8,
                        color: '#8fadcc',
                        textStyle: {
                            fontSize: 12,
                        },
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255,255,255,0.1)',
                        },
                    },
                    axisTick: {
                        show: false,
                    },
                    splitLine: {
                        show: false,
                    },
                },
                yAxis: [
                    {
                        axisLabel: {
                            color: '#8fadcc',
                            textStyle: {
                                fontSize: 12,
                            },
                            formatter: '{value}%',
                        },
                        axisLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(255,255,255,0.1)',
                            },
                        },
                        axisTick: {
                            show: false,
                        },
                        splitLine: {
                            show: false,
                        },
                    },
                ],
                series: [
                    {
                        type: 'bar',
                        name: '同期',
                        data: tmData,
                        barWidth: '6',
                        barGap: '80%',
                        itemStyle: {
                            normal: {
                                color: new this.$echarts.graphic.LinearGradient(
                                    0,
                                    0,
                                    0,
                                    1,
                                    [
                                        {
                                            offset: 0,
                                            color: 'rgba(51,185,255,1)',
                                        },
                                        {
                                            offset: 1,
                                            color: 'rgba(12,29,100,1)',
                                        },
                                    ]
                                ),
                            },
                        },
                    },
                    {
                        //分隔
                        type: 'pictorialBar',
                        itemStyle: {
                            color: '#00143f',
                        },
                        symbolRepeat: 'fixed',
                        symbolMargin: 2,
                        symbol: 'roundRect',
                        symbolClip: true,
                        symbolSize: [8, 1],
                        symbolPosition: 'start',
                        symbolOffset: [-5, 0],
                        data: tmData,
                        z: 10,
                        animationEasing: 'elasticOut',
                    },
                    {
                        type: 'bar',
                        name: '实际',
                        data: jdData,
                        barWidth: '6',
                        barGap: '80%',
                        itemStyle: {
                            normal: {
                                color: new this.$echarts.graphic.LinearGradient(
                                    0,
                                    0,
                                    0,
                                    1,
                                    [
                                        {
                                            offset: 0,
                                            color: '#ffd300',
                                        },
                                        {
                                            offset: 1,
                                            color: '#64331c',
                                        },
                                    ]
                                ),
                            },
                        },
                    },
                    {
                        //分隔
                        type: 'pictorialBar',
                        itemStyle: {
                            color: '#00143f',
                        },
                        symbolRepeat: 'fixed',
                        symbolMargin: 2,
                        symbol: 'roundRect',
                        symbolClip: true,
                        symbolSize: [8, 1],
                        symbolPosition: 'start',
                        symbolOffset: [5, 0],
                        data: jdData,
                        z: 10,
                        animationEasing: 'elasticOut',
                    },
                ],
            }
            _chart.setOption(_options)
        },
    },
    created() {},
    mounted() {
        this.chartInit()
    },
}
</script>
<style lang='less' scoped>
.chart {
    height: 165px;
    width: 400px;
}
.info {
    height: 30px;
    margin-bottom: 20px;
    overflow-y: scroll;
    font-size: 14px;
    line-height: 30px;
    color: #8fadcc;
}
.list {
    .item {
        width: 90px;
        height: 40px;
        background-image: url(../../../assets/img/home/box-bg-2.png);
        margin-bottom: 4px;
        .data {
            flex: 1;
            padding: 0 2px;
            text-align: center;
            .val {
                font-size: 16px;
                color: #33bbff;
                font-weight: bold;
                line-height: 40px;
            }
        }
    }
}
</style>
